package org.bing.engine.common.remoting;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

public class RemotingFactoryBean implements FactoryBean, InitializingBean {

    protected String serviceUrl;
    @SuppressWarnings("rawtypes")
    protected Class serviceInterface;
    protected Object serviceProxy;
    protected RemotingProxyFactory proxyFactory;

    @SuppressWarnings("unchecked")
    public void afterPropertiesSet() {
        serviceProxy = proxyFactory.create(serviceInterface, serviceUrl);
    }

    public Object getObject() throws Exception {
        return serviceProxy;
    }

    @SuppressWarnings("rawtypes")
    public Class getObjectType() {
        return serviceInterface;
    }

    public boolean isSingleton() {
        return true;
    }

    /** Set method for ioc */
    public void setServiceUrl(String serviceUrl) {
        this.serviceUrl = serviceUrl;
    }

    @SuppressWarnings("rawtypes")
    public void setServiceInterface(Class serviceInterface) {
        this.serviceInterface = serviceInterface;
    }

    public void setServiceProxy(Object serviceProxy) {
        this.serviceProxy = serviceProxy;
    }

    public void setProxyFactory(RemotingProxyFactory proxyFactory) {
        this.proxyFactory = proxyFactory;
    }

}
